/*
 * @Author: Islands 1430536748@qq.com
 * @Date: 2024-07-13 16:23:12
 * @LastEditors: 周洋 1430536748@qq.com
 * @LastEditTime: 2024-08-20 17:15:45
 * @version: 1.0.0
 * @Description: 全局配置 本地缓存
 */
import { defineStore } from 'pinia';
import { ILanguage, IWidgets, ITabs } from '@/types/index.d';
import zhCN from 'element-plus/es/locale/lang/zh-cn';
import { ThemeNameEnum, LoopColor, LoopColorHover, AnimateEnum } from '@/constant/config';
import { toRgba } from '@/utils/index';
import bg3 from '@/assets/image/wallpaper/bg3.jpg';

export const configStore = defineStore('config', {
    state: () => {
        return {
            Widgets: {
                language: {
                    label: "中文简体",
                    value: "zhCN",
                    icon: '#icon-zhongwen',
                    el: zhCN,
                },
                colors: ['#409eff', '#67c23a', '#e6a23c', '#f56c6c', '#909399'],
                layout: ThemeNameEnum.layout01,
                wallpaper: bg3,
                anime: [AnimateEnum.PULSE, AnimateEnum.RUBBER_BAND],
                tab: {
                    hide: true,
                    height: 30,
                    style: 'default'
                },
                asideWidth: 200,
                footer: {
                    hide: true,
                    height: 40
                }
            } as IWidgets,
            Tabs: {
                activeTab: '/dashboard',
                blackPath: ['/login'],
                tabList: []
            } as ITabs
        }
    },
    actions: {
        updateLanguage(row:ILanguage){
            this.Widgets.language=row;
            return;
        },
        /** 修改布局方法 */
        activeChange(value: string) {
            this.$state.Widgets.layout = value;
            return;
        },
        /** 更新壁纸 */
        updateWallpaper(val: any) {
            return this.$state.Widgets.wallpaper = val;
        },
        /** 标签栏显示开关 */
        updateTabHide(val: any) {
            return this.$state.Widgets.tab.hide = val;
        },
        /** 标签栏高度 */
        updateTabHeight(val: any) {
            return this.$state.Widgets.tab.height = val;
        },
        /** 更新侧边栏宽度 */
        updateAsideWidth(val: any) {
            return this.$state.Widgets.asideWidth = val;
        },
        updateFooterHide(val: any) {
            return this.$state.Widgets.footer.hide = val;
        },
        updateFooterHeight(val: any) {
            return this.$state.Widgets.footer.height = val;
        },
        /** 主题色修改方法 */
        pickerChange(val: number, el: string, evn: any) {
            this.$state.Widgets.colors[val] = evn;
            let rgbaColor = toRgba(evn);
            LoopColor(el).forEach(item => {
                document.documentElement.style.setProperty(item, rgbaColor)
            });
            LoopColorHover(el).forEach(item => {
                document.documentElement.style.setProperty(item, toRgba(evn, 0.2))
            });
        },
        /** 更新菜单选中值 */
        setActiveTab(path: string) {
            this.Tabs.activeTab = path;
        },
        /** 向tabList插入tab对象 */
        setTbaList(tab: any) {
            if (tab !== null || tab !== undefined) {
                this.Tabs.tabList.push(tab);
            }
            return;
        },
        /** 筛选tabList 并更新它 */
        setTabs(tab: any) {
            this.Tabs.tabList = tab
            return;
        },
    },
    persist: {
        storage: localStorage
    }
})